package com.simpleaccount.Add;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.simpleaccount.Common.Utils;
import com.simpleaccount.Db.DbUtils;
import com.simpleaccount.Entity.Category;
import com.simpleaccount.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by 超 on 2017/7/13.
 */

public class OutcomeFragment extends Fragment {

    @Bind(R.id.iv_common)
    ImageView ivCommon;
    @Bind(R.id.iv_food)
    ImageView ivFood;
    @Bind(R.id.iv_transport)
    ImageView ivTransport;
    @Bind(R.id.iv_study)
    ImageView ivStudy;
    @Bind(R.id.iv_medicine)
    ImageView ivMedicine;
    @Bind(R.id.iv_expansive)
    ImageView ivExpansive;
    @Bind(R.id.iv_entertainment)
    ImageView ivEntertainment;
    @Bind(R.id.iv_shopping)
    ImageView ivShopping;
    @Bind(R.id.iv_clothes)
    ImageView ivClothes;
    @Bind(R.id.iv_society)
    ImageView ivSociety;
    @Bind(R.id.iv_hotel)
    ImageView ivHotel;
    @Bind(R.id.iv_travel)
    ImageView ivTravel;
    @Bind(R.id.iv_loan)
    ImageView ivLoan;
    @Bind(R.id.iv_repair)
    ImageView ivRepair;
    @Bind(R.id.iv_other_outcome)
    ImageView ivOtherOutcome;

    public String category="一般";
    //    @Bind(R.id.tvsubmit_pay)
//    TextView tvsubmit_pay;
//    @Bind(R.id.et_money)
//    EditText number_pay;
//    @Bind(R.id.datepicker_pay)
//    DatePicker datePicker_pay;
//    @Bind(R.id.editText_pay)
//    EditText editText_pay;
//    @Bind(R.id.spinner_pay)
//    Spinner spinner_pay;
    public interface Callback
    {
        public void getCategory(String category);
    }

    public List<String> getData() {
        List<String> list = new ArrayList<>();
        for (Category e : DbUtils.getCategory(1)) {
            list.add(e.getName());
        }
        return list;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_outcome, container, false);
        ButterKnife.bind(this, view);
        //MySpinnerAdapter adapter = new MySpinnerAdapter(getActivity(), getData());
        //spinner_pay.setAdapter(adapter);
        Utils.setImage(ivCommon, "一般");
        Utils.setImage(ivFood, "餐饮");
        Utils.setImage(ivTransport, "出行");
        Utils.setImage(ivClothes, "服装");
        Utils.setImage(ivEntertainment, "娱乐");
        Utils.setImage(ivExpansive, "贵重品");
        Utils.setImage(ivHotel, "住宿");
        Utils.setImage(ivLoan, "还贷");
        Utils.setImage(ivMedicine, "医疗");
        Utils.setImage(ivRepair, "维修");
        Utils.setImage(ivTravel, "旅游");
        Utils.setImage(ivStudy, "学习");
        Utils.setImage(ivSociety, "人情");
        Utils.setImage(ivOtherOutcome, "其他");
        Utils.setImage(ivShopping, "购物");

        onclicked("一般");
        return view;

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        //ButterKnife.unbind(this);
        ButterKnife.unbind(this);
    }
    public  void onclicked(String str){
        getActivity().findViewById(R.id.ll_numberbackgroundcolor).setBackgroundColor(DbUtils.getCategory(str).getColor());
        ((TextView)getActivity().findViewById(R.id.tv_number)).setTextColor(Color.parseColor("#000000"));
        ((TextView)getActivity().findViewById(R.id.tv_money)).setTextColor(Color.parseColor("#000000"));
        ((TextView)getActivity().findViewById(R.id.tv_number)).setHintTextColor(Color.parseColor("#000000"));
        category=str;
    }

    @OnClick({R.id.iv_common, R.id.iv_food, R.id.iv_transport, R.id.iv_study, R.id.iv_medicine, R.id.iv_expansive, R.id.iv_entertainment, R.id.iv_shopping, R.id.iv_clothes, R.id.iv_society, R.id.iv_hotel, R.id.iv_travel, R.id.iv_loan, R.id.iv_repair, R.id.iv_other_outcome})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_common:
                onclicked("一般");
                break;
            case R.id.iv_food:
                onclicked("餐饮");
                break;
            case R.id.iv_transport:
                onclicked("出行");
                break;
            case R.id.iv_study:
               onclicked("学习");
                break;
            case R.id.iv_medicine:
                onclicked("医疗");
                break;
            case R.id.iv_expansive:
                onclicked("贵重品");
                break;
            case R.id.iv_entertainment:
                onclicked("娱乐");
                break;
            case R.id.iv_shopping:
                onclicked("购物");
                break;
            case R.id.iv_clothes:
                onclicked("服装");
                break;
            case R.id.iv_society:
                onclicked("人情");
                break;
            case R.id.iv_hotel:
                onclicked("住宿");
                break;
            case R.id.iv_travel:
                onclicked("旅游");
                break;
            case R.id.iv_loan:
                onclicked("还贷");
                break;
            case R.id.iv_repair:
                onclicked("维修");
                break;
            case R.id.iv_other_outcome:
                onclicked("其他");
                break;
        }
    }
    public void setCategory(OutcomeFragment.Callback callback){
        callback.getCategory(category);
    }
//    public void clicksubmit() {
//        Intent intent = getActivity().getIntent();
//
//        //向intent里添加数据
//        intent.putExtra("金额","-"+number_pay.getText().toString());
//        intent.putExtra("类别",spinner_pay.getSelectedItem().toString());
//        intent.putExtra("日期年",datePicker_pay.getYear());
//        intent.putExtra("日期月",datePicker_pay.getMonth());
//        intent.putExtra("日期日",datePicker_pay.getDayOfMonth());
//        intent.putExtra("备注",editText_pay.getText().toString());
//
//        getActivity().setResult(0,intent);
//        getActivity().finish();
//
//    }

//
//    @OnClick({R.id.tvsubmit_pay})
//    public void onViewClicked(View view) {
//        switch (view.getId()) {
//            case R.id.tvsubmit_pay:
//                clicksubmit();
//                break;
//        }
//    }
}
